package com.jade.linkong.controller;

import com.jade.common.annotation.Log;
import com.jade.common.core.controller.BaseController;
import com.jade.common.core.domain.AjaxResult;
import com.jade.common.core.page.TableDataInfo;
import com.jade.common.enums.BusinessType;
import com.jade.common.utils.poi.ExcelUtil;
import com.jade.linkong.domain.LkMatterAlarmLog;
import com.jade.linkong.service.ILkMatterAlarmLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 事项警报日志Controller
 * 
 * @author jade
 * @date 2020-07-23
 */
@Controller
@RequestMapping("/linkong/log")
public class LkMatterAlarmLogController extends BaseController
{
    private String prefix = "linkong/log";

    @Autowired
    private ILkMatterAlarmLogService lkMatterAlarmLogService;

    @RequiresPermissions("linkong:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询事项警报日志列表
     */
    @RequiresPermissions("linkong:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LkMatterAlarmLog lkMatterAlarmLog)
    {
        startPage();
        List<LkMatterAlarmLog> list = lkMatterAlarmLogService.selectLkMatterAlarmLogList(lkMatterAlarmLog);
        return getDataTable(list);
    }

    /**
     * 导出事项警报日志列表
     */
    @RequiresPermissions("linkong:log:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LkMatterAlarmLog lkMatterAlarmLog)
    {
        List<LkMatterAlarmLog> list = lkMatterAlarmLogService.selectLkMatterAlarmLogList(lkMatterAlarmLog);
        ExcelUtil<LkMatterAlarmLog> util = new ExcelUtil<LkMatterAlarmLog>(LkMatterAlarmLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 新增事项警报日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存事项警报日志
     */
    @RequiresPermissions("linkong:log:add")
    @Log(title = "事项警报日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LkMatterAlarmLog lkMatterAlarmLog)
    {
        return toAjax(lkMatterAlarmLogService.insertLkMatterAlarmLog(lkMatterAlarmLog));
    }

    /**
     * 修改事项警报日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LkMatterAlarmLog lkMatterAlarmLog = lkMatterAlarmLogService.selectLkMatterAlarmLogById(id);
        mmap.put("lkMatterAlarmLog", lkMatterAlarmLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存事项警报日志
     */
    @RequiresPermissions("linkong:log:edit")
    @Log(title = "事项警报日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LkMatterAlarmLog lkMatterAlarmLog)
    {
        return toAjax(lkMatterAlarmLogService.updateLkMatterAlarmLog(lkMatterAlarmLog));
    }

    /**
     * 删除事项警报日志
     */
    @RequiresPermissions("linkong:log:remove")
    @Log(title = "事项警报日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lkMatterAlarmLogService.deleteLkMatterAlarmLogByIds(ids));
    }

    @RequiresPermissions("linkong:log:remove")
    @Log(title = "事项警报日志", businessType = BusinessType.CLEAN)
    @PostMapping( "/clean")
    @ResponseBody
    public AjaxResult remove()
    {
        lkMatterAlarmLogService.cleanAlarmLog();
        return success();
    }
    
    /***
     * 
     * @Author wupujian
     * @Description 
     * @Date  2020/7/24 
     * @Param []
     * @return java.util.Map<java.lang.String,java.lang.Object>
     **/
    @PostMapping( "/selectListByProject")
    @ResponseBody
    public Map<String, List<LkMatterAlarmLog>> selectListByProject(LkMatterAlarmLog alarmLog){
       return lkMatterAlarmLogService.selectListByProject(alarmLog);
    }

    /**
     * 首页项目more
     */
    @GetMapping("/projectmore")
    public String projectmore( ModelMap mmap)
    {
        return prefix + "/project_log";
    }

}
